package libutil;
import java.io.*;

public class filewriter {
	
	
	protected String filename;
	public Writer writer;
    public String sautdeligne;
    
    public filewriter(){}
    
	public filewriter(String nom){
//		this.filename = nom;
//		try{
//		writer =  new PrintWriter(new BufferedWriter
//				   (new FileWriter(this.filename)));
//		}catch (Exception ex){
//			ex.printStackTrace();
//            System.out.println("An exception occurs "+ex.getMessage());
//		}
//	}
//        public void insereligne(String ligne){
//            this.writer.println(ligne);
//        }
//	public void close(){
//	    this.writer.close();
//	}
//        public PrintWriter getwriter(){
//            return this.writer;
//        }
		this.sautdeligne = System.getProperty("line.separator");
		OutputStream stream;
		try {
			stream = new FileOutputStream(nom);
			this.writer = new OutputStreamWriter(stream, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

        public void insereligne(String ligne) {
            try {
				this.writer.write(ligne+this.sautdeligne);
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        }
	public void close() {
	    try {
			this.writer.close();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
        public Writer getwriter(){
            return this.writer;
        }
}
